package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	ticker := time.NewTicker(2 * time.Second)
	defer func() {
		fmt.Println("aa")
		ticker.Stop()
	}()

	done := make(chan bool)

	var wg sync.WaitGroup
	wg.Add(1)

	go func() {
		for {
			select {
			case <-done:
				return
			case t := <-ticker.C:
				fmt.Println("Tick at", t)
			}
		}
		wg.Done()
	}()

	wg.Wait()
	fmt.Println("end")
}